package com.example.studyplanning.controller;

import com.example.studyplanning.entity.Clock;
import com.example.studyplanning.entity.Dislike;
import com.example.studyplanning.services.ClockServices;
import com.example.studyplanning.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("clock")
public class ClockController {
    @Autowired
    private ClockServices clockServices;

    //插入打卡信息
    @PostMapping("/add")
    public Result InsertClock(@RequestParam("userID") Integer userID){
        Result result = new Result();
        int i =clockServices.InsertClock(userID);
        if(i==1){
            result.setCode(200);
            result.setMessage("打卡成功");
        }else{
            result.setCode(400);
            result.setMessage("打卡失败");
        }
        return result;
    }

    //根据用户ID展示打卡人员信息
    @GetMapping("/list")
    public Result FindClock(@RequestParam("userID")Integer userID){
        Result result = new Result();
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(clockServices.FindClock(userID));
        return result;
    }

    //根据日期和用户ID展示信息
    @GetMapping("/lists")
    public  Result FindByDate(@RequestParam("userID") Integer userID,
                              @RequestParam("date_time") String date_time){
        Result result = new Result();
        List<Clock> list = clockServices.FindByDate(userID,date_time);
        if(list.size()==0){
            result.setCode(400);
            result.setMessage("未打卡");}
        else {
            result.setCode(200);
            result.setMessage("已打卡");
        }
        return result;
    }
}
